package com.chy.blog_server.modular.web.entity;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.chy.blog_server.core.util.UserUtil;
import com.chy.blog_server.modular.sharCore.BaseEntity;
import com.chy.blog_server.modular.system.entity.SysUser;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;


/**
 * 描述：时间线表 实体类
 * 作者：chenhuiyan
 * 时间：2020/04/06
 */
@Getter
@Setter
@TableName(value = "bo_time_line")
public class BoTimeLine extends BaseEntity {

    /**
     * 时间
     */
    @DateTimeFormat(pattern = "yyy-MM-dd")
    @TableField(value = "time_line")
    private Date timeLine;

    /**
     * 标题
     */
    private String title;

    /**
     * 备注
     */
    private String remark;

    /**
     * 添加数据时调用该方法生成
     * @param request
     */
    public void preInsert(HttpServletRequest request){
        SysUser user = UserUtil.getUserFromSession(request);
        if(ObjectUtil.isNotEmpty(user)){
            this.setCreateBy(user.getId());
            this.setUpdateBy(user.getId());
        }
        this.setId(IdUtil.simpleUUID());
        this.setCreateDate(new Date());
        this.setUpdateDate(new Date());
    }

    /**
     * 更新数据时调用该方法生成
     * @param request
     */
    public void preUpdate(HttpServletRequest request){
        SysUser user = UserUtil.getUserFromSession(request);
        if(ObjectUtil.isNotEmpty(user)){
            this.setUpdateBy(user.getId());
        }
        this.setUpdateDate(new Date());
    }

}
